import { request } from '@/utils/request'

export interface ArticleNav {
  id: number;
  title: string;
}

export interface NewsItem {
  id: number;
  title: string;
  image: string | null;
  publish_time: string;
  summary: string;
  html_content: string;
  click: number;
  category: string;
  prev?: ArticleNav | null;
  next?: ArticleNav | null;
}

export async function fetchNewsList(): Promise<NewsItem[]> {
  return await request('/api/news/', 'GET')
}

export async function fetchNewsDetail(id: number): Promise<NewsItem> {
  return await request(`/api/news/${id}/`, 'GET')
}

export async function incrementNewsClick(id: number) {
  return await request(`/api/news/${id}/increment_click/`, 'POST')
}